package com.sixteengroup.personnelms.service.personnel;

import com.sixteengroup.personnelms.bean.RecruitmentInfo;
import com.sixteengroup.personnelms.bean.Dept;
import com.sixteengroup.personnelms.dao.personnel.StaffMapper;
import com.sixteengroup.personnelms.dao.personnel.StaffRecruitmentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName DeptAndStaffService
 * @Author 陈新予(blank)
 * @Date 2021/8/13
 * @Version 1.0
 */
@Service
public class DeptAndStaffService {
    @Autowired
    StaffMapper staffMapper;
    @Autowired
    StaffRecruitmentMapper staffRecruitmentMapper;
    //获取全部的部门,部门员工关联在部门中
    public List<Dept> getAllDept(){
        return staffMapper.getAlldept();
    }
    //查询全部的招聘信息,关联人员
    public List<RecruitmentInfo> getAllRecInfo(){
        return staffRecruitmentMapper.getAllRecInfo();
    }
    //删除招聘信息
    public void deleteRecInfo(int id){
        staffRecruitmentMapper.deleteRecInfo(id);
    }
    //修改招聘信息
    public void updateRecInfo(int id,int res){
        if(res>=4){
            //在部门中加入该用户

            staffRecruitmentMapper.addRecInfo(id,4);
        }else {
            staffRecruitmentMapper.addRecInfo(id,res);
        }
    }

    public void saveStaffDept(int userId, String deptName) {
        int deptid = 0;
        if (deptName.equals("财务部")){
            deptid = 1;
        }else if (deptName.equals("人事部")){
            deptid = 2;
        }else if (deptName.equals("信息部")){
            deptid = 3;
        }else {
            deptid = 4;
        }
        staffRecruitmentMapper.saveStaffDept(userId,deptid);
        //将外部用户修改为内部用户
        staffRecruitmentMapper.updateUserStatus(userId);
        //保存人员流动日志
        staffRecruitmentMapper.saveStaffFlowLog(userId,deptid);
    }
}
